//
//  AppendXGFishpondTableViewCell.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/9/12.
//

#import "AppendXGFishpondTableViewCell.h"
#import "YTBaseEditorStringView.h"

@interface AppendXGFishpondTableViewCell ()

@property (nonatomic ,strong)  YTBaseEditorStringView * expectYield;
@property (nonatomic ,strong)  UIView * ytview;

@end
@implementation AppendXGFishpondTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self setupView];
    }
    return self;
}


- (void)setupView{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = KcolorHex(@"#ECEDEE");
    self.contentView.clipsToBounds = YES;
    self.userInteractionEnabled = YES;
    self.contentView.userInteractionEnabled = YES;
    
    UIView * topview = [UIView new];
    topview.backgroundColor = UIColor.whiteColor;
    [self.contentView addSubview:topview];
    [topview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(0);
        make.left.offset(0);
        make.height.offset(kwt(65));
        make.top.offset(0);
    }];
    MJWeakSelf
    YTBaseEditorStringView * expectYield = [YTBaseEditorStringView NewView];
    self.expectYield = expectYield;
    expectYield.forceFlag = NO;
    expectYield.keyboardType = UIKeyboardTypeNumberPad;
    expectYield.name = @"预计产量(斤)";
    expectYield.block = ^(NSString * _Nonnull content) {
        weakSelf.model.addPondModelList.firstObject.expectYield = content;
        weakSelf.model.expectYield = content;
    };
    [topview addSubview:expectYield];
    [expectYield mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(kwt(-10));
        make.left.offset(kwt(10));
        make.height.offset(kwt(60));
        make.top.offset(0);
    }];
    
    UIView * buttomview = [UIView new];
    [self addSubview:buttomview];
    buttomview.backgroundColor = KcolorHex(@"#ECEDEE");
    [buttomview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(65));
        make.bottom.offset(kwt(-10));
    }];
    
    UILabel * temp = [DTKTool labelWithText:@"同步设置其他池塘信息如下(不可变更其他池塘的池塘名称、编组和预计产量)：" andFont:kFont(15) andTextColor:KcolorHex(@"#6A6A6A")];
    temp.numberOfLines = 2;
    [buttomview addSubview:temp];
    [temp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(14));
        make.right.offset(kwt(-14));
        make.top.offset(kwt(15));
    }];
    
    UIView * bgview = [UIView new];
    bgview.backgroundColor = UIColor.whiteColor;
    [DTKTool YJBK:kwt(5) andView:bgview andWidth:0.5 andColor:KcolorHex(@"#E5E3E3")];
    [buttomview addSubview:bgview];
    [bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(10));
        make.bottom.right.offset(kwt(-10));
        make.top.offset(kwt(60));
    }];
    
    
    UIView * oneline = [UIView new];
    oneline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:oneline];
    [oneline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(50));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UILabel * onelab = [DTKTool labelWithText:@"数量" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    onelab.textAlignment = NSTextAlignmentCenter;
    [bgview addSubview:onelab];
    [onelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.equalTo(oneline.mas_left);
        make.top.offset(kwt(15));
    }];
    
    UIView * tweline = [UIView new];
    tweline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:tweline];
    [tweline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(134));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UILabel * twelab = [DTKTool labelWithText:@"池塘名称" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [bgview addSubview:twelab];
    [twelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(oneline.mas_right).offset(kwt(8));
        make.right.equalTo(tweline.mas_left);
        make.centerY.equalTo(onelab);
    }];
    
    UIView * threeline = [UIView new];
    threeline.backgroundColor = KcolorHex(@"#E5E3E3");
    [bgview addSubview:threeline];
    [threeline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(266));
        make.bottom.top.offset(0);
        make.width.offset(0.5);
    }];
    
    UILabel * threelab = [DTKTool labelWithText:@"池塘编组" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    [bgview addSubview:threelab];
    threelab.numberOfLines = 2;
    [threelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(tweline.mas_right).offset(kwt(8));
        make.right.equalTo(threeline.mas_left);
        make.centerY.equalTo(onelab);
    }];
    
    UILabel * fourlab = [DTKTool labelWithText:@"*池塘名称" andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
    fourlab.attributedText = [DTKTool AttributedStringWithStr:@"预计产量\n(斤)" andNodeColor:KcolorHex(@"#787A79") andSeledColor:KcolorHex(@"#787A79") andFont:kFont(15) andPattenr:@"[(斤)]"];
    [bgview addSubview:fourlab];
    fourlab.numberOfLines = 2;
    [fourlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(threeline.mas_right).offset(kwt(8));
        make.right.offset(0);
        make.centerY.equalTo(onelab);
    }];
    
    UIView * ytview = [UIView new];
    ytview.backgroundColor = UIColor.whiteColor;
    self.ytview = ytview;
    [bgview addSubview:ytview];
    [ytview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kwt(50));
        make.bottom.offset(kwt(-10));
    }];
    
}
- (void)setModel:(AddXGPondModel *)model{
    _model = model;
    NSString * firstexpectYield = @"";
    if(model.expectYield.length > 0){
        firstexpectYield = [NSString stringWithFormat:@"%@",model.expectYield];
    }
//    self.expectYield.content = [NSString stringWithFormat:@"%@", model.addPondModelList.firstObject.expectYield];
    self.expectYield.content = firstexpectYield;
    [self.ytview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    
    UIView * oneline = [UIView new];
    oneline.backgroundColor = KcolorHex(@"#E5E3E3");
    [self.ytview addSubview:oneline];
    [oneline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(50));
        make.top.bottom.offset(0);
        make.width.offset(0.5);
    }];
    
    UIView * tweline = [UIView new];
    tweline.backgroundColor = KcolorHex(@"#E5E3E3");
    [self.ytview addSubview:tweline];
    [tweline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(134));
        make.top.bottom.offset(0);
        make.width.offset(0.5);
    }];
    
    UIView * threeline = [UIView new];
    threeline.backgroundColor = KcolorHex(@"#E5E3E3");
    [self.ytview addSubview:threeline];
    [threeline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(kwt(266));
        make.top.bottom.offset(0);
        make.width.offset(0.5);
    }];
    
    CGFloat Y = 0;
    int i = 1;
    for (addPondModelListModel * pondmodel in model.addPondModelList) {
        
        UIView * line = [UIView new];
        line.backgroundColor = KcolorHex(@"#DDDDDD");
        [self.ytview addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.offset(0);
            make.top.offset(Y);
            make.height.offset(0.5);
        }];
     
        
        UILabel * onelab = [DTKTool labelWithText:[NSString stringWithFormat:@"%d",i] andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
        [self.ytview addSubview:onelab];
        [onelab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(kwt(10));
            make.right.equalTo(oneline.mas_left);
            make.centerY.equalTo(line.mas_top).offset(kwt(20));
        }];
        
       
        
        UILabel * twelab = [DTKTool labelWithText:pondmodel.name andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
        [self.ytview addSubview:twelab];
        [twelab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(oneline.mas_right).offset(kwt(8));
            make.right.equalTo(tweline.mas_left).offset(kwt(-8));
            make.centerY.equalTo(onelab);
        }];
        
     
        
        UILabel * threelab = [DTKTool labelWithText:pondmodel.tissueName andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
        [self.ytview addSubview:threelab];
        [threelab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(tweline.mas_right).offset(kwt(8));
            make.right.equalTo(threeline.mas_left).offset(kwt(-8));
            make.centerY.equalTo(onelab);
        }];
        NSString * expectYield = @"/";
        if(pondmodel.expectYield.length > 0){
            expectYield = [NSString stringWithFormat:@"%@",pondmodel.expectYield];
        }
        UILabel * fourlab = [DTKTool labelWithText:expectYield andFont:kFont(15) andTextColor:KcolorHex(@"#787A79")];
        [self.ytview addSubview:fourlab];
        [fourlab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(threeline.mas_right).offset(kwt(8));
            make.right.offset(kwt(-8));
            make.centerY.equalTo(onelab);
        }];
        
        Y += kwt(40);
        i++;
    }
    
    
    
}
@end
